﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class cambiarPassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) {
        Usuario user = (Usuario)this.Session["Usuario"];
        if (user == null)
        {
            Response.Redirect("noEstaLogeado.aspx", true);
        }
    }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Usuario user = (Usuario)this.Session["Usuario"];
        if (user == null)
        {
            Response.Redirect("noEstaLogeado.aspx", true);
        }
        String antipassword = user.getPassword();
        if (!apassword.Text.Equals(antipassword))
        {
            Label1.Text = "Error. No esta indicando su antigua password correctamente";
        }
        else if (!password1.Text.Equals(password2.Text))
        {
            Label1.Text = "Error. Los 2 campos del nuevo password deben ser identicos";
        }

        else
        {
            //apassword.Text = "";
            //password1.Text = "";
            //password2.Text = "";
            Label1.Text = "Enhorabuena, ha cambiado su contraseña.";
            GestionUsuarios.getInstance().cambiarpasswordusuario(user,password1.Text);
            user.setPassword(password1.Text);
            Session["Usuario"] = user;

        }

    }
}
